#include<stdio.h>
const int maxn=100010;
int gcd(int a,int b)
{
	if(a<0)  a=-a;
	if(b<0)  b=-b;
	if(a%b==0) return b;
	else  return gcd(b,a%b);
}
int main()
{
	int n,a[maxn],b[maxn],s[maxn];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		s[i]=gcd(a[i],b[i]);
	}
	for(int i=0;i<n;i++){
		printf("%d\n",s[i]);
	}
	return 0;
}
